package oa.hleast.xswl.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import oa.hleast.xswl.pojo.domain.SysDict;
import oa.hleast.xswl.pojo.domain.UmsMember;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;


@Mapper
public interface UmsUserMapper extends BaseMapper<UmsMember> {


    @Select("<script>" +
            " SELECT * from ums_user " +
            " <if test ='user.nickname !=null and user.nickname.trim() neq \"\" ' >" +
            "       AND nickname like concat('%',#{user.nickname},'%')" +
            " </if>" +
            " ORDER BY gmt_modified DESC, gmt_create DESC" +
            "</script>")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(property = "addressList", column = "id", many = @Many(select = "oa.hleast.interview.mapper.UmsAddressMapper.listByUserId"))
    })
    List<UmsMember> list(@Param("page") Page<UmsMember> page, @Param("user") UmsMember user);


    @Select("<script>" +
            "SELECT\n" +
            "\tb.`name` AS `name`,\n" +
            "\tcount( 1 ) AS `value` \n" +
            "FROM\n" +
            "\tums_user a\n" +
            "\tLEFT JOIN sys_dict_item b ON a.gender = b.`value` \n" +
            "WHERE\n" +
            "\tb.dict_code = 'gender' and a.gender != 0\n" +
            "GROUP BY\n" +
            "\tgender" +
            "</script>")
    List<Map<String, Object>> userGender();

    @Select("<script>" +
            "select id_card_num from ums_user where id_card_num is not null and (LENGTH(id_card_num) = 15 or LENGTH(id_card_num) = 18)" +
            "</script>")
    List<String> findAllIdCardNum();

    @Select("<script>" +
            "select * from sys_dict_item where dict_code = 'gender'" +
            "</script>")
    List<SysDict> getGenderDict();
}
